<?php

/**
 * This is the model class for table "order".
 *
 * The followings are the available columns in table 'order':
 * @property integer $id
 * @property integer $shopid
 * @property integer $productid
 * @property integer $userid
 * @property string $date
 * @property integer $quantity
 * @property integer $price
 * @property integer $isPaid
 * @property integer $isShip
 * @property integer $shipFee
 *
 * The followings are the available model relations:
 * @property Shop $shop
 * @property Product $product
 * @property User $user
 * @property Shipping[] $shippings
 */
class Order extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Order the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'order';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('shopid, productid, userid, quantity, price, isPaid, isShip, shipFee', 'numerical', 'integerOnly'=>true),
			array('date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, shopid, productid, userid, date, quantity, price, isPaid, isShip, shipFee', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'shop' => array(self::BELONGS_TO, 'Shop', 'shopid'),
			'product' => array(self::BELONGS_TO, 'Product', 'productid'),
			'user' => array(self::BELONGS_TO, 'User', 'userid'),
			'shippings' => array(self::HAS_MANY, 'Shipping', 'orderid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'shopid' => 'Shopid',
			'productid' => 'Productid',
			'userid' => 'Userid',
			'date' => 'Date',
			'quantity' => 'Quantity',
			'price' => 'Price',
			'isPaid' => 'Is Paid',
			'isShip' => 'Is Ship',
			'shipFee' => 'Ship Fee',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('shopid',$this->shopid);
		$criteria->compare('productid',$this->productid);
		$criteria->compare('userid',$this->userid);
		$criteria->compare('date',$this->date,true);
		$criteria->compare('quantity',$this->quantity);
		$criteria->compare('price',$this->price);
		$criteria->compare('isPaid',$this->isPaid);
		$criteria->compare('isShip',$this->isShip);
		$criteria->compare('shipFee',$this->shipFee);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}